package com.woniu.inlet.web;

import com.woniu.outlet.po.Person;
import com.woniu.outlet.po.PersonCompany;
import com.woniu.outlet.po.PersonExtend;
import com.woniu.outlet.po.PersonFamily;
import com.woniu.service.IPersonService;
import com.woniu.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cli")
@Api(tags = "个人客户信息处理")
public class PersonController {

    @Autowired
    private IPersonService personService;

    //这个是添加正式的个人用户的信息，这个有两个情况，一个是从潜在客户哪里申请来的，申请成功就会删除这个潜在客户的信息
    //还有一种就是从别的渠道获得的正式客户，不管哪一种情况都会在添加完正式客户之后发一条短信给客户本人
    @ApiOperation(value = "addpersoninfo",notes = "添加正式客户的信息")
    @PostMapping("/addpersoninfo")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> addpersoninfo(@RequestBody Person person){
        int addpersoninfo = personService.addpersoninfo(person);
        return new ResponseResult<>("添加正式客户成功！！",200);
    }


    //修改个人用户的信息
    @ApiOperation(value = "updatepersoninfo",notes = "修改个人用户的信息")
    @PostMapping("/updatepersoninfo")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> updatepersoninfo(@RequestBody Person person){
        int updatepersoninfo = personService.updatepersoninfo(person);
        return new ResponseResult<>("你已经修改成功!!",200);
    }


    //修改客户的扩展信息
    @ApiOperation(value = "updatepersonextend",notes = "修改客户的扩展信息")
    @PostMapping("/updatepersonextend")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> updatepersonextend(@RequestBody PersonExtend personExtend){
        int updatepersonextend = personService.updatepersonextend(personExtend);
        return new ResponseResult<>("修改成功！！",200);
    }

    //修改个人客户的公司信息
    @ApiOperation(value = "updatepersoncompany",notes = "修改个人客户的公司信息")
    @PostMapping("/updatepersoncompany")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> updatepersoncompany(@RequestBody PersonCompany personCompany){
        int updatepersoncompany = personService.updatepersoncompany(personCompany);
        return new ResponseResult<>("修改成功了！！",200);
    }

    //添加个人客户的家人信息（一对多的关系！）
    @ApiOperation(value = "addpersonfamily",notes = "添加个人客户的家人信息")
    @PostMapping("/addpersonfamily")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> addpersonfamily(@RequestBody PersonFamily personFamily){
        int addpersonfamily = personService.addpersonfamily(personFamily);
        return new ResponseResult<>("添加成功！！",200);
    }

    //修改个人客户的家人信息
    @ApiOperation(value = "updatepersonfamily",notes = "修改个人客户的家人信息")
    @PostMapping("/updatepersonfamily")
    @PreAuthorize("hasRole('client')")
    public ResponseResult<String> updatepersonfamily(@RequestBody PersonFamily personFamily){
        int updatepersonfamily = personService.updatepersonfamily(personFamily);
        return new ResponseResult<>("修改成功！！",200);
    }


}
